// GenericUtility.cpp: implementation of the GenericUtility class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "GenericUtility.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

GenericUtility::GenericUtility()
{
}

GenericUtility::~GenericUtility()
{
}

std::string GenericUtility::GetVersionInfo(HMODULE hModule, LPCTSTR lpszSubBlockName)
{
	char szName[1024];
	GetModuleFileName(hModule, szName, sizeof(szName));
	DWORD dwHandle;
	DWORD dwSize = GetFileVersionInfoSize(szName, &dwHandle);
	void * pvBlock = new BYTE[dwSize];
	GetFileVersionInfo(szName, dwHandle, dwSize, pvBlock);
	char * pszSubBlock = new char[25+strlen(lpszSubBlockName)+1];
	strcpy(pszSubBlock, "\\StringFileInfo\\080404b0\\");
	strcat(pszSubBlock, lpszSubBlockName);
	void * pvBuffer;
	UINT nBytes;
	VerQueryValue(pvBlock, _T(pszSubBlock), &pvBuffer, &nBytes);
	std::string strVersion = (LPCTSTR)pvBuffer;
	delete pszSubBlock;
	delete pvBlock;

	return strVersion;
}